<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的id号">
          <a-input placeholder="请输入货物的id号" v-decorator="['hwId', validatorRules.hwId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户的id号">
          <a-input placeholder="请输入用户的id号" v-decorator="['userId', validatorRules.userId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的类型标志">
          <a-input-number v-decorator="[ 'hwLxbz', validatorRules.hwLxbz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的名称">
          <a-input placeholder="请输入货物的名称" v-decorator="['hwMc', validatorRules.hwMc ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的照片链接">
          <a-input placeholder="请输入货物的照片链接" v-decorator="['hwZplj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的重量">
          <a-input placeholder="请输入货物的重量" v-decorator="['hwZl', validatorRules.hwZl ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的体积">
          <a-input placeholder="请输入货物的体积" v-decorator="['hwTj', validatorRules.hwTj ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的装货地区">
          <a-input placeholder="请输入货物的装货地区" v-decorator="['hwZhdq', validatorRules.hwZhdq ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的装货详情的地址">
          <a-input placeholder="请输入货物的装货详情的地址" v-decorator="['hwZhxxdz', validatorRules.hwZhxxdz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的卸货地区">
          <a-input placeholder="请输入货物的卸货地区" v-decorator="['hwXhdq', validatorRules.hwXhdq ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的卸货详细地址">
          <a-input placeholder="请输入货物的卸货详细地址" v-decorator="['hwXhxxdz', validatorRules.hwXhxxdz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的装货坐标">
          <a-input placeholder="请输入货物的装货坐标" v-decorator="['hwZhzb', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的卸货坐标">
          <a-input placeholder="请输入货物的卸货坐标" v-decorator="['hwXhzb', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的用车类型标志">
          <a-input-number v-decorator="[ 'hwYclxbz', validatorRules.hwYclxbz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的用车车长标志">
          <a-input-number v-decorator="[ 'hwYcccbz', validatorRules.hwYcccbz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物用车车长">
          <a-input placeholder="请输入货物用车车长" v-decorator="['hwYccc', validatorRules.hwYccc ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的运输类型标志">
          <a-input-number v-decorator="[ 'hwYslxbz', validatorRules.hwYslxbz ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的装货日期时间">
          <a-input placeholder="请输入货物的装货日期时间" v-decorator="['hwZhrqsj', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物的状态，默认为0,0表示刚发布，1表示删除，2表示发起接单请求，3表示发起签署协议请求，4表示签署协议，5表示装货，6表示运输中，7表示到达目的地，8表示卸货，9表示完成">
          <a-input-number v-decorator="[ 'hwZt', validatorRules.hwZt ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="期望运费，默认为0">
          <a-input placeholder="请输入期望运费，默认为0" v-decorator="['hwQwyf', validatorRules.hwQwyf ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="货物发布的日期时间">
          <a-input placeholder="请输入货物发布的日期时间" v-decorator="['hwFbrqsj', validatorRules.hwFbrqsj ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "HwModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        hwId:{rules: [{ required: true, message: '请输入货物的id号!' }]},
        userId:{rules: [{ required: true, message: '请输入用户的id号!' }]},
        hwLxbz:{rules: [{ required: true, message: '请输入货物的类型标志!' }]},
        hwMc:{rules: [{ required: true, message: '请输入货物的名称!' }]},
        hwZl:{rules: [{ required: true, message: '请输入货物的重量!' }]},
        hwTj:{rules: [{ required: true, message: '请输入货物的体积!' }]},
        hwZhdq:{rules: [{ required: true, message: '请输入货物的装货地区!' }]},
        hwZhxxdz:{rules: [{ required: true, message: '请输入货物的装货详情的地址!' }]},
        hwXhdq:{rules: [{ required: true, message: '请输入货物的卸货地区!' }]},
        hwXhxxdz:{rules: [{ required: true, message: '请输入货物的卸货详细地址!' }]},
        hwYclxbz:{rules: [{ required: true, message: '请输入货物的用车类型标志!' }]},
        hwYcccbz:{rules: [{ required: true, message: '请输入货物的用车车长标志!' }]},
        hwYccc:{rules: [{ required: true, message: '请输入货物用车车长!' }]},
        hwYslxbz:{rules: [{ required: true, message: '请输入货物的运输类型标志!' }]},
        hwZt:{rules: [{ required: true, message: '请输入货物的状态，默认为0,0表示刚发布，1表示删除，2表示发起接单请求，3表示发起签署协议请求，4表示签署协议，5表示装货，6表示运输中，7表示到达目的地，8表示卸货，9表示完成!' }]},
        hwQwyf:{rules: [{ required: true, message: '请输入期望运费，默认为0!' }]},
        hwFbrqsj:{rules: [{ required: true, message: '请输入货物发布的日期时间!' }]},
        },
        url: {
          add: "/hw/hw/add",
          edit: "/hw/hw/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'hwId','userId','hwLxbz','hwMc','hwZplj','hwZl','hwTj','hwZhdq','hwZhxxdz','hwXhdq','hwXhxxdz','hwZhzb','hwXhzb','hwYclxbz','hwYcccbz','hwYccc','hwYslxbz','hwZhrqsj','hwZt','hwQwyf','hwFbrqsj'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>